package com.hdmall.business.common.util;

import java.util.Calendar;
import java.util.Date;

public class NumberUtil {



    //创建订单编号
    public static Long createOrderNo(Integer dealerId){
        return createNo(0, dealerId);
    }

    //创建计划编号
    public static Long createPlanNo(Integer dealerId){
        return createNo(1, dealerId);
    }

    //创建orderItemId
    public static Long createOrderItem(Integer dealerId){
        return createNo(4,  dealerId);
    }
    //发货编号
    public  static long createFufillmentNo(Integer dealerId){
        return createNo(2, dealerId);
    }

    public static long createMessageNo(Integer dealerId){
        return createNo(3, dealerId);
    }
    //竞拍编号
    public static long createAuctionNo(Integer dealerId){
        return createNo(5, dealerId);
    }
    //IM聊天消息
    public static long createIMMessageNo(){
        return createNo(5, 1);
    }

    public static long createGroupNo(Integer dealerId){
        return createNo(4, dealerId);
    }

    //通用方法
    private static Long createNo(Integer type, Integer dealerId){

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String number = "";
        String year = calendar.get(Calendar.YEAR) + "";
        Integer intMonth = calendar.get(Calendar.MONTH) + 1;
        String month = intMonth <= 9 ? "" + "0" + intMonth : "" + intMonth;
        Integer intDay = calendar.get(Calendar.DAY_OF_MONTH);
        String day = intDay <= 9 ? "0" + intDay : "" + intDay;
        Integer intMini = calendar.getTime().getMinutes();
        String minite = intMini <= 9 ? "" + "0" + intMini : "" + intMini;

        String random = "";
        for(int i = 0; i <= 3; i++){
            int time = (int) (Math.random() * 9999);
                random += time % 9 + "";
        }

        String dealerIdStr = dealerId <= 9 ? "" + "0" + dealerId : "" + dealerId;

        number += year + month + day + minite + dealerIdStr + random + type ;
        return Long.valueOf(number);
    }

    public static void main(String []args){

        Calendar calendar = Calendar.getInstance();
//        System.out.println(createOrderNo(1));
//    System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(createNo(1, 11));
    }
}
